//
//  WebPageNavBar.m
//  ZhiHuDaily
//
//  Created by 吴宜昊 on 2022/2/6.
//

#import "WebPageNavBar.h"
#import "WebPageDelegate.h"

@interface WebPageNavBar ()
@property(nonatomic,strong) UIButton * btnBack;
@property(nonatomic,weak) id<WebPageDelegate> delegate;
@end
@implementation WebPageNavBar

#pragma mark - override
-(instancetype) initWithFrame:(CGRect) frame delegate:(id<WebPageDelegate>) delegate {
    self = [super initWithFrame:frame];
    if (self) {
        self.delegate = delegate;
        [self setupUI];
    }
    return self;
}

-(void) updateConstraints {
    [self remakeMas];
    [super updateConstraints];
}

#pragma mark - remakeMas
-(void) remakeMas {
    // WeakSelf(self);
    [self.btnBack mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@16);
        make.centerY.equalTo(@0);
        make.width.height.equalTo(@44);
    }];
    
}

#pragma mark - override
-(void) setupUI {
    [self addSubview:self.btnBack];
    [self setNeedsUpdateConstraints];
    self.backgroundColor = RGBA(222, 222, 222, 0.76);
}

#pragma mark - lazy
-(UIButton *) btnBack {
    if (!_btnBack) {
        _btnBack = [UIButton buttonWithType:UIButtonTypeCustom];
        [_btnBack setImage: IMAGE(@"Back")  forState:UIControlStateNormal];
        [_btnBack addTarget:self action:@selector(actBack) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btnBack;
}

#pragma mark - action
-(void) actBack {
    if (_delegate && [_delegate respondsToSelector:@selector(webPageDelegateBack) ] ) {
        [_delegate webPageDelegateBack];
    }
}

@end
